package com.taotao.order.controller;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.bean.TaotaoResult;
import com.taotao.order.pojo.Order;
import com.taotao.order.service.OrderService;

@Controller
@ResponseBody
//@RequestMapping("/order")
public class OrderController {

	@Autowired
	private OrderService orderService;

	/**
	 * 接受一个json格式的字符串作为参数 使用@requestbody注解
	 * 
	 * @param order
	 * @return
	 */
	@RequestMapping("/create")
	TaotaoResult createOrder(@RequestBody Order order) {
		try {
			TaotaoResult result = orderService.creatOrder(order, order.getOrderItems(), order.getOrderShipping());
			return result;

		} catch (Exception e) {
			e.printStackTrace();
			return TaotaoResult.build(500, ExceptionUtils.getStackTrace(e));
		}

	}

}
